<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Search extends CI_Controller{
    public function __construct() {
        parent::__construct();
        $this->load->model('Search_model');
        $this->load->model('Interviewer_model');
        $this->load->model('Function_model');
        $this->load->model('Staff_model');
        $this->load->model('Cv_model');
        $this->load->model('Login_model');
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->library('pagination');
    }
    public function index()
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $Lab_ID=$this->security->sanitize_filename($this->input->post('txtLabID'));
        if($Lab_ID==0)
        {
            $Lab_ID = $this->uri->segment(3);
            //$Searchkey=$this->uri->segment(4);
        }
        $start_row = $this->uri->segment(4);
        $per_page = 10;
        $config['base_url'] =base_url().'search/index/'.$Lab_ID;
        $query=$this->Search_model->searchResult($Lab_ID);
        $config['total_rows'] = $query->num_rows();
        $data['total_rows']=$query->num_rows();
        $config['uri_segment'] = 4;
        $config['per_page'] = $per_page;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();
        $data['title_content']="Manage Staff and Salary";
        $data['query'] = $this->Search_model->searchResultLimited($Lab_ID,$per_page,$start_row);
        $Lab_ID=array('Lab_ID'=>$Lab_ID);
        $this->session->set_userdata($Lab_ID);
        //$data['keyword']=$Searchkey;
        $this->load->view('_header',$data);
        $this->load->view('search/getResultSearch'); 
        $this->load->view('_footer');
    }
    public function searchbykeyword()
    {
        $email=$this->session->userdata('email');
        $data['email']=$email;
        $keyword=$this->security->sanitize_filename($this->input->post('keyword'));

        if($keyword=="")
        {
            $keyword = $this->uri->segment(3);
            //$Searchkey=$this->uri->segment(4);
        } else {
            $keyword = urldecode($keyword);
        }
        $start_row = $this->uri->segment(4);
        $per_page = 10;
        $config['base_url'] = base_url().'search/searchbykeyword/'.$keyword;
        $query=$this->Search_model->searchByKeyword(urldecode($keyword));
        $config['total_rows'] = $query->num_rows();
        $data['total_rows']=$query->num_rows();
        $config['uri_segment'] = 4;
        $config['per_page'] = $per_page;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();
        $data['title_content']="Manage Staff and Salary";
        
        $data['query'] = $this->Search_model->searchByKeywordLimited(urldecode($keyword),$per_page,$start_row);
        /*if(strlen(strstr($keyword, "%20")))
        {
        $chuoi=explode("%20", $keyword);
        $searchkey=$chuoi[0].' '.$chuoi[1];
        //echo $searchkey;
        }
        else {
        $chuoi=explode(" ", $keyword);
        $searchkey=$chuoi[0].' '.$chuoi[1];
        //echo $searchkey;
        }*/
        $keyword1=array('keyword'=>urldecode($keyword));
        $this->session->set_userdata($keyword1);
        //$data['keyword']=$Searchkey;
        $this->load->view('_header',$data);
        $this->load->view('search/getResultSearch'); 
        $this->load->view('_footer');
    }
    /*public function getuser()
    {
        $q=$_GET["q"];
        $sql="select * from Lab where Lab_ID='".$q."'";
        $query=$this->db->query($sql);

        echo "<table border='1'>
        <tr>
        <th>LabName</th>
        </tr>";

        foreach ($query->result() as $row)
        {
        echo "<tr>";
        echo "<td>" . $row->LabName . "</td>";
        echo "</tr>";
        }
        echo "</table>";
   }*/
 }
?>
